#!/bin/sh

AC_PREREQ(2.60)
AC_INIT
AC_CONFIG_SRCDIR(.version)
AC_CONFIG_HEADER(ddconfig.h:ddconfig_in.h custom.h:custom_in.h)

AC_PROG_AWK

AC_MSG_CHECKING(version of the package)
if test -f ${srcdir}/.version; then
  { read VERSION; } < ${srcdir}/.version
  AC_MSG_RESULT($VERSION)
else
  VERSION="0.0.0"
  AC_MSG_RESULT(unknown using 0.0.0)
fi
VERSIONHI=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $1}'`
VERSIONLO=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $2}'`
VERSIONP=`echo $VERSION|$AWK 'BEGIN {FS="."} {print $3}'`
AC_SUBST(VERSION)
AC_SUBST(VERSIONHI)
AC_SUBST(VERSIONLO)
AC_SUBST(VERSIONP)
AC_DEFINE_UNQUOTED(VERSIONSTR, "${VERSION}", [XXX])
AC_DEFINE_UNQUOTED(VERSIONHI, $VERSIONHI, [XXX])
AC_DEFINE_UNQUOTED(VERSIONLO, $VERSIONLO, [XXX])
AC_DEFINE_UNQUOTED(VERSIONP, $VERSIONP, [XXX])

# Some options
#==============
# *nix default: "${datadir}/sdcc/doc"
AC_ARG_VAR(docdir, documentation installation directory)
if test "${docdir}" = ""; then
    docdir="\${datadir}"/sdcc/doc
fi
AC_SUBST(docdir)

AC_ARG_ENABLE(ucsim,
[  --enable-ucsim          compile ucsim frontend],
if test $enable_ucsim != "no"; then
    enable_ucsim="yes"
fi,
#default
enable_ucsim="no")
AC_ARG_ENABLE(dlso,
[  --enable-dlso           compile dynamically loadable shared libraries],
if test $enable_dlso != "no"; then
    enable_dlso="yes"
fi,
enable_dlso="no")
AC_ARG_ENABLE(51,
[  --disable-51            do not compile simulator for MCS51],
if test $enable_51 != "no"; then
    enable_51="yes"
fi,
enable_51="yes")
AC_ARG_ENABLE(avr,
[  --disable-avr           do not compile simulator for AVR],
if test $enable_avr != "no"; then
    enable_avr="yes"
fi,
enable_avr="yes")
AC_ARG_ENABLE(z80,
[  --disable-z80           do not compile simulator for Z80],
if test $enable_z80 != "no"; then
    enable_z80="yes"
fi,
enable_z80="yes")
AC_ARG_ENABLE(hc08,
[  --disable-hc08          do not compile simulator for hc08],
if test $enable_hc08 != "no"; then
    enable_hc08="yes"
fi,
enable_hc08="yes")
AC_ARG_ENABLE(pblaze,
[  --disable-pblaze          do not compile simulator for PicoBlaze],
if test $enable_pblaze != "no"; then
    enable_pblaze="yes"
fi,
enable_pblaze="yes")
AC_ARG_ENABLE(xa,
[  --enable-xa             compile simulator for XA],
if test $enable_xa != "no"; then
    enable_xa="yes"
fi,
enable_xa="no")
AC_ARG_ENABLE(portmon,
[  --enable-serio          compile serio GUI tool (needs curses)],
if test $enable_serio != "no"; then
    enable_serio="yes"
fi,
enable_serio="no")
AC_SUBST(enable_ucsim)
AC_SUBST(enable_dlso)
AC_SUBST(enable_51)
AC_SUBST(enable_avr)
AC_SUBST(enable_z80)
AC_SUBST(enable_hc08)
AC_SUBST(enable_pblaze)
AC_SUBST(enable_xa)
AC_SUBST(enable_serio)

AC_ARG_ENABLE(statistic,
[  --enable-statistic      compile statistical features (slower simulation)],
if test $enable_statistic != "no"; then
   enable_statistic="yes"
fi,
enable_statistic="no")
AC_DEFINE_UNQUOTED(STATISTIC, $enable_statistic, [XXX])


# Required programs
#-------------------
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_INSTALL
AC_PROG_RANLIB
dnl AC_LANG_CPLUSPLUS

AC_CHECK_PROG(STRIP, strip, strip, :)

AC_LIBTOOL_DLOPEN
dnl AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

AC_PROG_LEX
if test ${LEX} = "flex"; then
        AC_DEFINE(HAVE_FLEX, 1, [XXX])
fi
AC_PROG_YACC
AC_CHECK_PROG(BISON_PLUS_PLUS, bison++, bison++, :)


AC_LANG_CPLUSPLUS

# Checking for header files.
# ===========================================================================

if test -d /stuff/include; then
  CPPFLAGS="$CPPFLAGS -I/stuff/include"
fi

AC_HEADER_STDC
AC_CHECK_HEADERS(endian.h sys/endian.h machine/endian.h sys/isa_defs.h)
AC_CHECK_HEADERS(getopt.h unistd.h termios.h)

AC_CHECK_HEADER(curses.h,
  AC_DEFINE(HAVE_CURSES_H, 1, [XXX])
  curses_h_ok=yes,
  curses_h_ok=no
)

ucsim_cv_socket="unknown"
AC_CHECK_HEADER(sys/socket.h,
  AC_DEFINE(HAVE_SYS_SOCKET_H, 1, [XXX])
  AC_DEFINE(SOCKET_AVAIL, 1, [XXX])
  AC_DEFINE_UNQUOTED(UCSOCKET_T, int, [XXX])
  ucsim_cv_socket="<sys/socket.h>"
)

WINSOCK_AVAIL=0
if test $ucsim_cv_socket = unknown; then
  AC_CHECK_HEADER(winsock2.h,
    AC_DEFINE(HAVE_WINSOCK2_H, 1, [XXX])
    AC_DEFINE(SOCKET_AVAIL, 1, [XXX])
    AC_DEFINE_UNQUOTED(UCSOCKET_T, SOCKET, [XXX])
    ucsim_cv_socket="<winsock2.h>"
    WINSOCK_AVAIL=1
  )
fi
AC_SUBST(WINSOCK_AVAIL)

if test $ucsim_cv_socket != unknown; then
  AC_EGREP_HEADER(socklen_t,
    $ucsim_cv_socket,
    AC_DEFINE_UNQUOTED(SOCKLEN_T, socklen_t, [XXX]),
    AC_DEFINE_UNQUOTED(SOCKLEN_T, uint, [XXX]))
fi
AC_DEFINE_UNQUOTED(HEADER_SOCKET, ${ucsim_cv_socket}, [XXX])

AC_CHECK_HEADER(dlfcn.h)
AC_HEADER_DIRENT

# This must be after CXXCPP

AC_CACHE_CHECK(which header file defines FD_ macros, ucsim_cv_fd,
[ucsim_cv_fd="unknown"
AC_EGREP_CPP(yes, [
#include <winsock2.h>
#ifdef FD_ZERO
yes
#endif], ucsim_cv_fd="<winsock2.h>")
AC_EGREP_CPP(yes, [
#include <sys/time.h>
#ifdef FD_ZERO
yes
#endif], ucsim_cv_fd="<sys/time.h>")
AC_EGREP_CPP(yes, [
#include <sys/types.h>
#ifdef FD_ZERO
yes
#endif], ucsim_cv_fd="<sys/types.h>")
AC_EGREP_CPP(yes, [
#include <sys/select.h>
#ifdef FD_ZERO
yes
#endif], ucsim_cv_fd="<sys/select.h>")])

ucsim_cv_header_ok=0
if echo $ucsim_cv_fd|grep time >/dev/null 2>&1; then
AC_DEFINE(FD_NEED_TIME_H, 1, [XXX])
ucsim_cv_header_ok=1
else
AC_DEFINE(FD_NEED_TIME_H, 0, [XXX])
fi
if echo $ucsim_cv_fd|grep types >/dev/null 2>&1; then
AC_DEFINE(FD_NEED_TYPES_H, 1, [XXX])
ucsim_cv_header_ok=1
else
AC_DEFINE(FD_NEED_TYPES_H, 0, [XXX])
fi
if echo $ucsim_cv_fd|grep select >/dev/null 2>&1; then
AC_DEFINE(FD_NEED_SELECT_H, 1, [XXX])
ucsim_cv_header_ok=1
else
AC_DEFINE(FD_NEED_SELECT_H, 0, [XXX])
fi
if echo $ucsim_cv_fd|grep winsock2 >/dev/null 2>&1; then
AC_DEFINE(FD_NEED_WINSOCK2_H, 1, [XXX])
ucsim_cv_header_ok=1
else
AC_DEFINE(FD_NEED_WINSOCK2_H, 0, [XXX])
fi

AC_DEFINE_UNQUOTED(FD_HEADER_OK, ${ucsim_cv_header_ok}, [XXX])
AC_DEFINE_UNQUOTED(HEADER_FD, ${ucsim_cv_fd}, [XXX])


# Checking for functions/libs
# ===========================================================================
if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then
  LIBS="-lws2_32 $LIBS"
else
  AC_CHECK_LIB(socket,socket)
  AC_CHECK_LIB(nsl,xdr_short)
fi

AC_CHECK_LIB(dl,dlopen,
dl_ok="yes"
DL="-ldl",
dl_ok="no"
DL="")
AC_SUBST(dl_ok)
AC_SUBST(DL)

#AC_CHECK_LIB(panel,panel_above,
#panel_ok="yes"
#curses_ok="yes"
#CURSES_LIBS="-lpanel -lcurses"
#,
#panel_ok="no"
#AC_CHECK_LIB(curses,nl,
#curses_ok="yes"
#CURSES_LIBS="-lcurses"
#,
#curses_ok="no")
#,
#-lcurses)

if test $curses_h_ok != yes; then
  panel_ok="no"
  curses_ok="no"
else
  AC_CHECK_LIB(panel,panel_above,
    panel_ok="yes"
    curses_ok="yes"
    CURSES_LIBS="-lpanel",
    panel_ok="no"
    curses_ok="no"
  )

  if test $curses_ok != yes; then
    AC_CHECK_LIB(curses,nl,
      curses_ok="yes"
      CURSES_LIBS="-lcurses",
      curses_ok="no")
  fi

  if test $curses_ok != yes; then
    AC_CHECK_LIB(ncurses,nl,
      curses_ok="yes"
      CURSES_LIBS="-lncurses",
      curses_ok="no")
  fi
fi

AC_SUBST(panel_ok)
AC_SUBST(curses_ok)
AC_SUBST(CURSES_LIBS)

AC_FUNC_VPRINTF
AC_CHECK_FUNCS(vsnprintf)
AC_CHECK_FUNCS(_vsnprintf)
AC_CHECK_FUNCS(vasprintf)
AC_CHECK_FUNCS(strlen strcpy strcat strstr strcmp strerror strtok strdup)
AC_CHECK_FUNCS(strchr memcpy)
dnl AC_CHECK_FUNCS(getline)
dnl AC_CHECK_FUNCS(getdelim)
AC_CHECK_FUNCS(fgets)
AC_CHECK_FUNCS(yylex)

AC_CACHE_CHECK(whether scanf knows %a, ucsim_cv_scanf_a,
[echo "a b" >conftest.data
AC_TRY_RUN([
#include <stdio.h>
void main(void)
{
  FILE *f;
  char *a;
  int  i;
  if ((f= fopen("conftest.data", "r")) == NULL)
    exit(1);
  i= fscanf(f, " %a[a-z] ", &a);
  fclose(f);
  if (i == 0)
    exit(2);
  if (i == 1)
    exit(0);
  exit(3);
}],
ucsim_cv_scanf_a="yes",
ucsim_cv_scanf_a="no",
ucsim_cv_scanf_a="unknown")
])
if test "$ucsim_cv_scanf_a" = "yes"; then
  AC_DEFINE(SCANF_A, 1, [XXX])
fi

AC_CACHE_CHECK(whether getcwd is GNUish, ucsim_cv_getcwd,
[AC_TRY_RUN([
#include <unistd.h>
void main(void)
{
  if ((getcwd(NULL, 0)) == NULL)
    exit(1);
  exit(0);
}],
ucsim_cv_getcwd="yes",
ucsim_cv_getcwd="no",
ucsim_cv_getcwd="unknown")
])
if test "$ucsim_cv_getcwd" = "yes"; then
  AC_DEFINE(GNU_GETCWD, 1, [XXX])
fi

AC_DEFUN([ucsim_ACCEPT_LENGTH_T],
 [AC_CACHE_CHECK([for type of length pointer parameter of accept],
   ucsim_cv_accept_length_type,
   [ac_save_CPPFLAGS="$CPPFLAGS"
    ucsim_cv_accept_length_type=no
    for ac_val in int size_t socklen_t; do
      CPPFLAGS="$ac_save_CPPFLAGS -DACCEPT_SOCKLEN_T=$ac_val"
      AC_TRY_COMPILE([#include <sys/types.h>
#include ${ucsim_cv_socket}],
        [struct sockaddr a; $ac_val len; accept (0, &a, &len);],
        [ucsim_cv_accept_length_type=$ac_val; break])
    done
    CPPFLAGS="$ac_save_CPPFLAGS"])
  if test "$ucsim_cv_accept_length_type" != no; then
    AC_DEFINE_UNQUOTED(ACCEPT_SOCKLEN_T, $ucsim_cv_accept_length_type,
      [Define to be the type of length parameter of accept (without the \*').])
  fi
 ]
)
#'

ucsim_ACCEPT_LENGTH_T

# Macro definitions
###################

# Check whether the compiler for the current language is SunPRO.

AC_DEFUN([bor_IS_SUNPRO],
[AC_CACHE_CHECK([whether we are using the SunPRO _AC_LANG compiler],
  [bor_cv_[]_AC_LANG_ABBREV[]_compiler_sunpro],
  [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#if !defined __SUNPRO_C && !defined __SUNPRO_CC
       choke me
#endif
]])],
    [bor_compiler_sunpro=yes],
    [bor_compiler_sunpro=no])
bor_cv_[]_AC_LANG_ABBREV[]_compiler_sunpro=$bor_compiler_sunpro
])])

# bor_IS_VALID_OPTION macro checks if the current compiler, selected by
# AC_LANG, supports option specified as the 1st parameter. The test fails if
# the compiler returns an error or in case something is writeen to stderr.
# For example: bor_VALID_OPT(fPIC)

AC_DEFUN([bor_IS_VALID_OPTION],
[ac_test_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
bor_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
AC_CACHE_CHECK(whether $_AC_LANG_PREFIX accepts -$1, bor_cv_[]_AC_LANG_ABBREV[]_$1,
  [bor_save_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
   ac_[]_AC_LANG_ABBREV[]_werror_flag=yes

   []_AC_LANG_PREFIX[]FLAGS="-$1"
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
     [bor_cv_[]_AC_LANG_ABBREV[]_$1=yes],
     [bor_cv_[]_AC_LANG_ABBREV[]_$1=no])
   ac_[]_AC_LANG_ABBREV[]_werror_flag=$bor_save_[]_AC_LANG_ABBREV[]_werror_flag])
   []_AC_LANG_PREFIX[]FLAGS=$bor_save_[]_AC_LANG_PREFIX[]FLAGS
])

# Checking characteristics of compilers and other programs
# --------------------------------------------------------

# Cross compiling overrides
# FIXME
if test "$CC" = "i586-mingw32msvc-gcc"; then
  ac_cv_c_bigendian=no
  ac_cv_sizeof_char=1
  ac_cv_sizeof_short=2
  ac_cv_sizeof_int=4
  ac_cv_sizeof_long=4
  ac_cv_sizeof_long_long=4
fi

# SDCC_BUILD_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN])
# -------------------------------------------------------------------------
AC_DEFUN([SDCC_BUILD_BIGENDIAN],
[AC_CACHE_CHECK(whether host machine byte ordering is bigendian, sdcc_cv_build_bigendian,
[# See if sys/param.h defines the BYTE_ORDER macro.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
#include <sys/param.h>
],
[#if  ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \
	&& BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN)
 bogus endian macros
#endif
])],
[# It does; now see whether it defined to BIG_ENDIAN or not.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
#include <sys/param.h>
], [#if BYTE_ORDER != BIG_ENDIAN
 not big endian
#endif
])], [sdcc_cv_build_bigendian=yes], [sdcc_cv_build_bigendian=no])],
[# It does not; compile a test program.
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], [[
  /* Are we little or big endian?  From Harbison&Steele.  */
  union
  {
    long int l;
    char c[sizeof (long int)];
  } u;
  u.l = 1;
  return u.c[sizeof (long int) - 1] == 1;
]])],
	      [sdcc_cv_build_bigendian=no],
	      [sdcc_cv_build_bigendian=yes],
[# try to guess the endianness by grepping values into an object file
  sdcc_cv_build_bigendian=unknown
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }]],
[[ _ascii (); _ebcdic (); ]])],
[if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
  sdcc_cv_build_bigendian=yes
fi
if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
  if test "$sdcc_cv_build_bigendian" = unknown; then
    sdcc_cv_build_bigendian=no
  else
    # finding both strings is unlikely to happen, but who knows?
    sdcc_cv_build_bigendian=unknown
  fi
fi])])])])
case $sdcc_cv_build_bigendian in
  yes)
    m4_default([$1],
      [AC_DEFINE([BUILD_WORDS_BIGENDIAN], 1,
	[Define to 1 if your processor stores words with the most significant
	 byte first (like Motorola and SPARC, unlike Intel and VAX).])]) ;;
  no)
    $2 ;;
  *)
    m4_default([$3],
      [AC_MSG_ERROR([unknown endianness
presetting sdcc_cv_build_bigendian=no (or yes) will help])]) ;;
esac
])# SDCC_BUILD_BIGENDIAN

SDCC_BUILD_BIGENDIAN

PICOPT=""
SHAREDLIB="no"

if test "$ac_cv_cxx_compiler_gnu" = "yes"; then
  AC_CACHE_CHECK(whether preprocessor accepts -MM or -M,ucsim_cv_MM,
  echo "#include <stdio.h>" >_test_.c
  echo "" >>_test_.c
  $CXXCPP -v -MM _test_.c 1>&5 2>&5
  if test "$?" = "0"; then
    ucsim_cv_MM="-MM"
  else
    ucsim_cv_MM="-M"
  fi
  rm -f _test_.*)

  # This is the first time when CFLAGS are set/modified!!

  bor_IS_VALID_OPTION(ggdb)
  bor_IS_VALID_OPTION(gstabs)
  if test "$ucsim_cv_cxx_gstabs" = "yes"; then
    gopt="-gstabs+ -g3"
  elif test "$ucsim_cv_cxx_ggdb" = "yes"; then
    gopt="-ggdb -g3"
  else
    gopt="-g"
  fi
  if test "$CXXFLAGS"x = x ;then
    CXXFLAGS="$gopt"
  else
    CXXFLAGS="$CXXFLAGS $gopt"
  fi

  bor_IS_VALID_OPTION(pipe)
  if test "$ucsim_cv_cxx_pipe" = "yes"; then
    CXXFLAGS="$CXXFLAGS -pipe"
  fi

  MAKEDEP="$CXX $ucsim_cv_MM"
  WALL_FLAG="-Wall"
else
  bor_IS_SUNPRO
  if test "$bor_cv_cxx_compiler_sunpro" = "yes"; then
    CXXFLAGS="-xO2 $CXXFLAGS"
    MAKEDEP="$CXX -xM1"
    WALL_FLAG=
  fi
fi

# pic_flag is defined by AC_PROG_LIBTOOL
PICOPT=$pic_flag

if test "$PICOPT"x != "x"; then
    SHAREDLIB="yes"
fi
AC_SUBST(MAKEDEP)
AC_SUBST(WALL_FLAG)
AC_SUBST(SHAREDLIB)
AC_SUBST(PICOPT)

dlso_ok="no"
if test $SHAREDLIB = "yes" -a $dl_ok = "yes" -a $enable_dlso = "yes"; then
    dlso_ok="yes"
fi
AC_SUBST(dlso_ok)

# Checks for typedefs, structures, and compiler characteristics.
# ===========================================================================

AC_TYPE_SIGNAL
if test "$cross_compiling" = "no"; then
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
else
    if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
        ac_cv_sizeof_char=1
        ac_cv_sizeof_short=2
        ac_cv_sizeof_int=4
        ac_cv_sizeof_long=4
        ac_cv_sizeof_long_long=4
    else
        : # FIXME
    fi
#echo
fi

type_name()
{
    if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
        echo "char"
        exit
    fi
    if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
        echo "short"
        exit
    fi
    if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
        echo "int"
        exit
    fi
    if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
        echo "long"
        exit
    fi
    if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then
        echo "long long"
        exit
    fi
    echo "long long"
}

AC_MSG_CHECKING(type name for byte)
TYPE_BYTE=`type_name 1`
AC_MSG_RESULT($TYPE_BYTE)
AC_MSG_CHECKING(type name for word)
TYPE_WORD=`type_name 2`
AC_MSG_RESULT($TYPE_WORD)
AC_MSG_CHECKING(type name for dword)
TYPE_DWORD=`type_name 4`
AC_MSG_RESULT($TYPE_DWORD)
AC_DEFINE_UNQUOTED(TYPE_BYTE, [$TYPE_BYTE], [XXX])
AC_DEFINE_UNQUOTED(TYPE_WORD, [$TYPE_WORD], [XXX])
AC_DEFINE_UNQUOTED(TYPE_DWORD, [$TYPE_DWORD], [XXX])
AC_DEFINE_UNQUOTED(TYPE_UBYTE, [unsigned $TYPE_BYTE], [XXX])
AC_DEFINE_UNQUOTED(TYPE_UWORD, [unsigned $TYPE_WORD], [XXX])
AC_DEFINE_UNQUOTED(TYPE_UDWORD, [unsigned $TYPE_DWORD], [XXX])

AH_TOP([#ifndef DDCONFIG_HEADER
#define DDCONFIG_HEADER])
AH_BOTTOM([#include "custom.h"
#endif /* DDCONFIG_HEADER */])

if echo $TYPE_DWORD|grep short >/dev/null; then
    A="h"
elif echo $TYPE_DWORD|grep long >/dev/null; then
    A="l"
else
    A=""
fi

if echo $TYPE_WORD|grep short >/dev/null; then M="h"
elif echo $TYPE_WORD|grep long >/dev/null; then M="l"
else M=""
fi

AC_DEFINE_UNQUOTED(_A_, "${A}", [XXX])
AC_DEFINE_UNQUOTED(_M_, "${M}", [XXX])

# Generating output files
# ===========================================================================

AC_OUTPUT(Makefile
main.mk:main_in.mk
packages.mk:packages_in.mk
sim.src/Makefile
cmd.src/Makefile
s51.src/Makefile
avr.src/Makefile
z80.src/Makefile
hc08.src/Makefile
pblaze.src/Makefile
xa.src/Makefile
gui.src/Makefile
gui.src/serio.src/Makefile
doc/Makefile
)

#gui.src/portmon.src/Makefile


# End of configure/configure.in
